package com.chen.authority.controller;

import com.chen.authority.common.response.Response;
import com.chen.authority.model.dto.UpdatePwdDto;
import com.chen.authority.model.dto.UserInfoDto;
import com.chen.authority.service.UserCenterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

/**
 * 用户中心
 *
 * @author chengy
 * @date 2022/11/26
 */
@Api(tags = "用户中心 UserCenterController")
@RequiredArgsConstructor
@RestController
@RequestMapping("/user-center")
public class UserCenterController {

    private final UserCenterService userCenterService;

    @PutMapping("/avatar")
    @ApiOperation("更新当前登录用户头像")
    public Response update(@ApiParam(value = "上传头像", required = true) MultipartFile file) {
        return userCenterService.updateUserAvatar(file);
    }

    @PutMapping("/info")
    @ApiOperation("更新当前登录用户信息")
    public Response update(@Valid @RequestBody UserInfoDto dto) {
        return userCenterService.updateUserInfo(dto);
    }

    @PutMapping("/password")
    @ApiOperation("更新密码")
    public Response update(@Valid @RequestBody UpdatePwdDto dto) {
        return userCenterService.updateUserPwd(dto);
    }

}
